<template>
	<view class="background safe-area-inset-bottom">
		1111
		<view>
			<achievements></achievements>
		</view>
		<!-- <view style="margin: 22rpx 36rpx;margin-bottom: 0;">
			<search :service="searchService"></search>
		</view>
		<view style="flex: 1;min-height: 0;">
			<mescroll-view ref="mescrollview" @down="downCallback"  @up="upCallback">
				<view style="margin: 20rpx 36rpx 0 36rpx;">
					<banner :service="bannerService"></banner>
				</view>
				<view style="margin: 29rpx 36rpx 0 36rpx;">
					<category :service="categoryService"></category>
				</view>
				<view style="margin: 63rpx 36rpx 0 36rpx;">
					<categorylist :service="categorylistService"></categorylist>
				</view>
			</mescroll-view>
		</view> -->
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	
	import achievements from '@/pagesHome/home/homeItem/achievements/achievements.vue'
	
	import Service from './service.js'
	import model from './model.js'

	/*********************************search***************************************/
	import search from './components/searchbar/searchbar.vue'
	import SearchService from './components/searchbar/service.js'
	/*********************************banner***************************************/
	import banner from './components/banner/banner.vue'
	import BannerService from './components/banner/service.js'
	/*********************************category***************************************/
	import category from './components/category/category.vue'
	import CategoryService from './components/category/service.js'
	/*********************************categorylist***************************************/
	import categorylist from './components/categorylist/categorylist.vue'
	import CategorylistService from './components/categorylist/service.js'
	export default {
		components: {
			achievements,
			search,
			banner,
			category,
			categorylist
		},
		data() {
			return {
				/********course********/
				service: new Service(this.$u),
				searchService:new SearchService(),
				bannerService:new BannerService(model.banner),
				categoryService:new CategoryService(model.category),
				categorylistService:new CategorylistService(model.categorylist)
			}
		},
		created() {
			/********************search*********************/
			this.searchService.search=()=>{
				console.log(11223344)
			}
			/********************category*********************/
			this.categoryService.itemClick=(index)=>{
				uni.navigateTo({
					url:'pagesShop/allcategory/allcategory',
					success: (res) => {
						res.eventChannel.emit('categateDataFromShophome', {category:this.categoryService.data,category_id:this.categoryService.data[index].id})
					}
				})
			}
			/********************categorylistService*********************/
			this.categorylistService.moreClick=(index)=>{
				uni.navigateTo({
					url:'pagesShop/allcategory/allcategory',
					success: (res) => {
						res.eventChannel.emit('categateDataFromShophome', {category:this.categoryService.data,category_id:this.categorylistService.data[index].id})
					}
				})
			}
			this.categorylistService.itemClick=(index,i)=>{
				this.$u.route({
					url:'pagesShop/details/details',
					params:{
						id:this.categorylistService.data[index].list[i].id
					}
				})
			}
		},
		onLoad() {
			this.downCallback()
		},
		methods: {
			/*下拉刷新的回调 */
			async downCallback() {
				// 这里加载你想下拉刷新的数据, 比如刷新轮播数据
				// loadSwiper();
				// 下拉刷新的回调,默认重置上拉加载列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
				try{
					// await this.service.lunboList(this.bannerService)
					// await this.service.cateList(this.categoryService)
					// await this.service.cateProductList(this.categorylistService)
					
				}catch(e){
					this.$refs.mescrollview.mescroll.endErr();
					this.$refs.uToast.show({
						title: e.message,
						type: 'error'
					});
				}
				// this.$refs.mescrollview.mescroll.resetUpScroll()
			},
			async upCallback(page) {
				this.$refs.mescrollview.mescroll.endErr();
				try {
					// await this.service.courseList(this.courseService, {
					// 	name: this.courseService.keyword,
					// 	page: page.num
					// }, res => {
					// 	this.mescroll.endSuccess(res.length);
					// })
				} catch (e) {
					this.mescroll.endErr();
					this.$refs.uToast.show({
						title: e.message,
						type: 'error'
					});
				}
			}
		}
	}
</script>

<style>
	page {
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;
	}

	page::before {
		content: '';
		position: fixed;
		left: 0;
		top: 0;
		width: 100%;
		height: 2rpx;
		background-color: #F8F8F8;
		z-index: 9999;
	}

	.background {
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;
	}
</style>
<style lang="scss" scoped>
	/deep/ .mescroll-empty .empty-icon {
		width: 512rpx;
		height: 560rpx;
	}
</style>
